<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="24">
        <el-form>
          <el-form-item label="报告类型:">
            <el-radio-group v-model="format">
              <el-radio label="week">周分析报告</el-radio>
              <el-radio label="month">月分析报告</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="报告时间:">
            <el-date-picker
              v-model="date"
              :picker-options="{ firstDayOfWeek: 1 }"
              :type="format === 'week' ? 'date' : 'month'"
              :format="format === 'week' ? 'yyyy-MM-dd' : 'yyyy-MM'"
              autocomplete="off"
              :clearable="false"></el-date-picker>
            <span>&emsp;&emsp; {{ $moment(date).format('yyyy年') + '第' + week + '周' }}</span>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-button type="success" @click="getList">分析</el-button>
  </div>
</template>

<script>
import { listComprehensiveAnalysis } from '@/api/production/execl'
import { downloadFileXls } from '@/utils/ruoyi'
export default {
  name: 'AllAnalyse',
  data() {
    return {
      format: 'week',
      date: this.$moment(),
    }
  },
  created() {},
  computed: {
    week() {
      const date = this.$moment(this.date)
      const day = date.dayOfYear()
      // 1月1日是星期几
      const firstW = this.$moment(date.year() + '-01-01').weekday()
      return '' + Math.ceil((this.$moment(this.date).dayOfYear() + firstW) / 7)
    },
  },
  methods: {
    getList() {
      const t = this.format === 'week' ? this.$moment(this.date).format('yyyy-') + this.week : this.$moment(this.date).format('yyyy-MM')
      listComprehensiveAnalysis(this.format, { time: t }).then((res) => {
        downloadFileXls(res, '综合分析报表')
      })
    },
  },
}
</script>
